3 * Proxy backend that mirrors writes to several internal backends.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup FileBackend
25 * @brief Proxy backend that mirrors writes to several internal backends.
27 * This class defines a multi-write backend. Multiple backends can be
28 * registered to this proxy backend and it will act as a single backend.
29 * Use this when all access to those backends is through this proxy backend.
30 * At least one of the backends must be declared the "master" backend.
32 * Only use this class when transitioning from one storage system to another.
34 * Read operations are only done on the 'master' backend for consistency.
35 * Write operations are performed on all backends, starting with the master.
36 * This makes a best-effort to have transactional semantics, but since requests
37 * may sometimes fail, the use of "autoResync" or background scripts to fix
38 * inconsistencies is important.
40 * @ingroup FileBackend
43 class FileBackendMultiWrite
extends FileBackend
{
44 /** @var FileBackendStore[] Prioritized list of FileBackendStore objects */
45 protected $backends = [];
47 /** @var int Index of master backend */
48 protected $masterIndex = -1;
49 /** @var int Index of read affinity backend */
50 protected $readIndex = -1;
52 /** @var int Bitfield */
53 protected $syncChecks = 0;
54 /** @var string|bool */
55 protected $autoResync = false;
58 protected $asyncWrites = false;
60 /* Possible internal backend consistency checks */
66 * Construct a proxy backend that consists of several internal backends.
67 * Locking, journaling, and read-only checks are handled by the proxy backend.
69 * Additional $config params include:
70 * - backends : Array of backend config and multi-backend settings.
71 * Each value is the config used in the constructor of a
72 * FileBackendStore class, but with these additional settings:
73 * - class : The name of the backend class
74 * - isMultiMaster : This must be set for one backend.
75 * - readAffinity : Use this for reads without 'latest' set.
76 * - syncChecks : Integer bitfield of internal backend sync checks to perform.
77 * Possible bits include the FileBackendMultiWrite::CHECK_* constants.
78 * There are constants for SIZE, TIME, and SHA1.
79 * The checks are done before allowing any file operations.
80 * - autoResync : Automatically resync the clone backends to the master backend
81 * when pre-operation sync checks fail. This should only be used
82 * if the master backend is stable and not missing any files.
83 * Use "conservative" to limit resyncing to copying newer master
84 * backend files over older (or non-existing) clone backend files.
85 * Cases that cannot be handled will result in operation abortion.
86 * - replication : Set to 'async' to defer file operations on the non-master backends.
87 * This will apply such updates post-send for web requests. Note that
88 * any checks from "syncChecks" are still synchronous.
91 * @suppress PhanAccessMethodProtected
93 * @param array $config
94 * @throws FileBackendError
96 public function __construct( array $config ) {
97 parent
::__construct( $config );
98 $this->syncChecks
= $config['syncChecks'] ?? self
::CHECK_SIZE
;
99 $this->autoResync
= $config['autoResync'] ??
false;
100 $this->asyncWrites
= isset( $config['replication'] ) && $config['replication'] === 'async';
101 // Construct backends here rather than via registration
102 // to keep these backends hidden from outside the proxy.
104 foreach ( $config['backends'] as $index => $config ) {
105 $name = $config['name'];
106 if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
107 throw new LogicException( "Two or more backends defined with the name $name." );
109 $namesUsed[$name] = 1;
110 // Alter certain sub-backend settings for sanity
111 unset( $config['readOnly'] ); // use proxy backend setting
112 unset( $config['fileJournal'] ); // use proxy backend journal
113 unset( $config['lockManager'] ); // lock under proxy backend
114 $config['domainId'] = $this->domainId
; // use the proxy backend wiki ID
115 if ( !empty( $config['isMultiMaster'] ) ) {
116 if ( $this->masterIndex
>= 0 ) {
117 throw new LogicException( 'More than one master backend defined.' );
119 $this->masterIndex
= $index; // this is the "master"
120 $config['fileJournal'] = $this->fileJournal
; // log under proxy backend
122 if ( !empty( $config['readAffinity'] ) ) {
123 $this->readIndex
= $index; // prefer this for reads
125 // Create sub-backend object
126 if ( !isset( $config['class'] ) ) {
127 throw new InvalidArgumentException( 'No class given for a backend config.' );
129 $class = $config['class'];
130 $this->backends
[$index] = new $class( $config );
132 if ( $this->masterIndex
< 0 ) { // need backends and must have a master
133 throw new LogicException( 'No master backend defined.' );
135 if ( $this->readIndex
< 0 ) {
136 $this->readIndex
= $this->masterIndex
; // default
140 final protected function doOperationsInternal( array $ops, array $opts ) {
141 $status = $this->newStatus();
143 $mbe = $this->backends
[$this->masterIndex
]; // convenience
145 // Try to lock those files for the scope of this function...
147 if ( empty( $opts['nonLocking'] ) ) {
148 // Try to lock those files for the scope of this function...
149 /** @noinspection PhpUnusedLocalVariableInspection */
150 $scopeLock = $this->getScopedLocksForOps( $ops, $status );
151 if ( !$status->isOK() ) {
152 return $status; // abort
155 // Clear any cache entries (after locks acquired)
157 $opts['preserveCache'] = true; // only locked files are cached
158 // Get the list of paths to read/write...
159 $relevantPaths = $this->fileStoragePathsForOps( $ops );
160 // Check if the paths are valid and accessible on all backends...
161 $status->merge( $this->accessibilityCheck( $relevantPaths ) );
162 if ( !$status->isOK() ) {
163 return $status; // abort
165 // Do a consistency check to see if the backends are consistent...
166 $syncStatus = $this->consistencyCheck( $relevantPaths );
167 if ( !$syncStatus->isOK() ) {
168 wfDebugLog( 'FileOperation', static::class .
169 " failed sync check: " . FormatJson
::encode( $relevantPaths ) );
170 // Try to resync the clone backends to the master on the spot...
171 if ( $this->autoResync
=== false
172 ||
!$this->resyncFiles( $relevantPaths, $this->autoResync
)->isOK()
174 $status->merge( $syncStatus );
176 return $status; // abort
179 // Actually attempt the operation batch on the master backend...
180 $realOps = $this->substOpBatchPaths( $ops, $mbe );
181 $masterStatus = $mbe->doOperations( $realOps, $opts );
182 $status->merge( $masterStatus );
183 // Propagate the operations to the clone backends if there were no unexpected errors
184 // and if there were either no expected errors or if the 'force' option was used.
185 // However, if nothing succeeded at all, then don't replicate any of the operations.
186 // If $ops only had one operation, this might avoid backend sync inconsistencies.
187 if ( $masterStatus->isOK() && $masterStatus->successCount
> 0 ) {
188 foreach ( $this->backends
as $index => $backend ) {
189 if ( $index === $this->masterIndex
) {
190 continue; // done already
193 $realOps = $this->substOpBatchPaths( $ops, $backend );
194 if ( $this->asyncWrites
&& !$this->hasVolatileSources( $ops ) ) {
195 // Bind $scopeLock to the callback to preserve locks
196 DeferredUpdates
::addCallableUpdate(
197 function () use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
198 wfDebugLog( 'FileOperationReplication',
199 "'{$backend->getName()}' async replication; paths: " .
200 FormatJson
::encode( $relevantPaths ) );
201 $backend->doOperations( $realOps, $opts );
205 wfDebugLog( 'FileOperationReplication',
206 "'{$backend->getName()}' sync replication; paths: " .
207 FormatJson
::encode( $relevantPaths ) );
208 $status->merge( $backend->doOperations( $realOps, $opts ) );
212 // Make 'success', 'successCount', and 'failCount' fields reflect
213 // the overall operation, rather than all the batches for each backend.
214 // Do this by only using success values from the master backend's batch.
215 $status->success
= $masterStatus->success
;
216 $status->successCount
= $masterStatus->successCount
;
217 $status->failCount
= $masterStatus->failCount
;
223 * Check that a set of files are consistent across all internal backends
225 * @param array $paths List of storage paths
226 * @return StatusValue
228 public function consistencyCheck( array $paths ) {
229 $status = $this->newStatus();
230 if ( $this->syncChecks
== 0 ||
count( $this->backends
) <= 1 ) {
231 return $status; // skip checks
234 // Preload all of the stat info in as few round trips as possible...
235 foreach ( $this->backends
as $backend ) {
236 $realPaths = $this->substPaths( $paths, $backend );
237 $backend->preloadFileStat( [ 'srcs' => $realPaths, 'latest' => true ] );
240 $mBackend = $this->backends
[$this->masterIndex
];
241 foreach ( $paths as $path ) {
242 $params = [ 'src' => $path, 'latest' => true ];
243 $mParams = $this->substOpPaths( $params, $mBackend );
244 // Stat the file on the 'master' backend
245 $mStat = $mBackend->getFileStat( $mParams );
246 if ( $this->syncChecks
& self
::CHECK_SHA1
) {
247 $mSha1 = $mBackend->getFileSha1Base36( $mParams );
251 // Check if all clone backends agree with the master...
252 foreach ( $this->backends
as $index => $cBackend ) {
253 if ( $index === $this->masterIndex
) {
256 $cParams = $this->substOpPaths( $params, $cBackend );
257 $cStat = $cBackend->getFileStat( $cParams );
258 if ( $mStat ) { // file is in master
259 if ( !$cStat ) { // file should exist
260 $status->fatal( 'backend-fail-synced', $path );
263 if ( $this->syncChecks
& self
::CHECK_SIZE
) {
264 if ( $cStat['size'] != $mStat['size'] ) { // wrong size
265 $status->fatal( 'backend-fail-synced', $path );
269 if ( $this->syncChecks
& self
::CHECK_TIME
) {
270 $mTs = wfTimestamp( TS_UNIX
, $mStat['mtime'] );
271 $cTs = wfTimestamp( TS_UNIX
, $cStat['mtime'] );
272 if ( abs( $mTs - $cTs ) > 30 ) { // outdated file somewhere
273 $status->fatal( 'backend-fail-synced', $path );
277 if ( $this->syncChecks
& self
::CHECK_SHA1
) {
278 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) { // wrong SHA1
279 $status->fatal( 'backend-fail-synced', $path );
283 } else { // file is not in master
284 if ( $cStat ) { // file should not exist
285 $status->fatal( 'backend-fail-synced', $path );
295 * Check that a set of file paths are usable across all internal backends
297 * @param array $paths List of storage paths
298 * @return StatusValue
300 public function accessibilityCheck( array $paths ) {
301 $status = $this->newStatus();
302 if ( count( $this->backends
) <= 1 ) {
303 return $status; // skip checks
306 foreach ( $paths as $path ) {
307 foreach ( $this->backends
as $backend ) {
308 $realPath = $this->substPaths( $path, $backend );
309 if ( !$backend->isPathUsableInternal( $realPath ) ) {
310 $status->fatal( 'backend-fail-usable', $path );
319 * Check that a set of files are consistent across all internal backends
320 * and re-synchronize those files against the "multi master" if needed.
322 * @param array $paths List of storage paths
323 * @param string|bool $resyncMode False, True, or "conservative"; see __construct()
324 * @return StatusValue
326 public function resyncFiles( array $paths, $resyncMode = true ) {
327 $status = $this->newStatus();
329 $mBackend = $this->backends
[$this->masterIndex
];
330 foreach ( $paths as $path ) {
331 $mPath = $this->substPaths( $path, $mBackend );
332 $mSha1 = $mBackend->getFileSha1Base36( [ 'src' => $mPath, 'latest' => true ] );
333 $mStat = $mBackend->getFileStat( [ 'src' => $mPath, 'latest' => true ] );
334 if ( $mStat === null ||
( $mSha1 !== false && !$mStat ) ) { // sanity
335 $status->fatal( 'backend-fail-internal', $this->name
);
336 wfDebugLog( 'FileOperation', __METHOD__
337 . ': File is not available on the master backend' );
338 continue; // file is not available on the master backend...
340 // Check of all clone backends agree with the master...
341 foreach ( $this->backends
as $index => $cBackend ) {
342 if ( $index === $this->masterIndex
) {
345 $cPath = $this->substPaths( $path, $cBackend );
346 $cSha1 = $cBackend->getFileSha1Base36( [ 'src' => $cPath, 'latest' => true ] );
347 $cStat = $cBackend->getFileStat( [ 'src' => $cPath, 'latest' => true ] );
348 if ( $cStat === null ||
( $cSha1 !== false && !$cStat ) ) { // sanity
349 $status->fatal( 'backend-fail-internal', $cBackend->getName() );
350 wfDebugLog( 'FileOperation', __METHOD__
.
351 ': File is not available on the clone backend' );
352 continue; // file is not available on the clone backend...
354 if ( $mSha1 === $cSha1 ) {
355 // already synced; nothing to do
356 } elseif ( $mSha1 !== false ) { // file is in master
357 if ( $resyncMode === 'conservative'
358 && $cStat && $cStat['mtime'] > $mStat['mtime']
360 $status->fatal( 'backend-fail-synced', $path );
361 continue; // don't rollback data
363 $fsFile = $mBackend->getLocalReference(
364 [ 'src' => $mPath, 'latest' => true ] );
365 $status->merge( $cBackend->quickStore(
366 [ 'src' => $fsFile->getPath(), 'dst' => $cPath ]
368 } elseif ( $mStat === false ) { // file is not in master
369 if ( $resyncMode === 'conservative' ) {
370 $status->fatal( 'backend-fail-synced', $path );
371 continue; // don't delete data
373 $status->merge( $cBackend->quickDelete( [ 'src' => $cPath ] ) );
378 if ( !$status->isOK() ) {
379 wfDebugLog( 'FileOperation', static::class .
380 " failed to resync: " . FormatJson
::encode( $paths ) );
387 * Get a list of file storage paths to read or write for a list of operations
389 * @param array $ops Same format as doOperations()
390 * @return array List of storage paths to files (does not include directories)
392 protected function fileStoragePathsForOps( array $ops ) {
394 foreach ( $ops as $op ) {
395 if ( isset( $op['src'] ) ) {
396 // For things like copy/move/delete with "ignoreMissingSource" and there
397 // is no source file, nothing should happen and there should be no errors.
398 if ( empty( $op['ignoreMissingSource'] )
399 ||
$this->fileExists( [ 'src' => $op['src'] ] )
401 $paths[] = $op['src'];
404 if ( isset( $op['srcs'] ) ) {
405 $paths = array_merge( $paths, $op['srcs'] );
407 if ( isset( $op['dst'] ) ) {
408 $paths[] = $op['dst'];
412 return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
416 * Substitute the backend name in storage path parameters
417 * for a set of operations with that of a given internal backend.
419 * @param array $ops List of file operation arrays
420 * @param FileBackendStore $backend
423 protected function substOpBatchPaths( array $ops, FileBackendStore
$backend ) {
424 $newOps = []; // operations
425 foreach ( $ops as $op ) {
426 $newOp = $op; // operation
427 foreach ( [ 'src', 'srcs', 'dst', 'dir' ] as $par ) {
428 if ( isset( $newOp[$par] ) ) { // string or array
429 $newOp[$par] = $this->substPaths( $newOp[$par], $backend );
439 * Same as substOpBatchPaths() but for a single operation
441 * @param array $ops File operation array
442 * @param FileBackendStore $backend
445 protected function substOpPaths( array $ops, FileBackendStore
$backend ) {
446 $newOps = $this->substOpBatchPaths( [ $ops ], $backend );
452 * Substitute the backend of storage paths with an internal backend's name
454 * @param array|string $paths List of paths or single string path
455 * @param FileBackendStore $backend
456 * @return array|string
458 protected function substPaths( $paths, FileBackendStore
$backend ) {
460 '!^mwstore://' . preg_quote( $this->name
, '!' ) . '/!',
461 StringUtils
::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
462 $paths // string or array
467 * Substitute the backend of internal storage paths with the proxy backend's name
469 * @param array|string $paths List of paths or single string path
470 * @return array|string
472 protected function unsubstPaths( $paths ) {
474 '!^mwstore://([^/]+)!',
475 StringUtils
::escapeRegexReplacement( "mwstore://{$this->name}" ),
476 $paths // string or array
481 * @param array $ops File operations for FileBackend::doOperations()
482 * @return bool Whether there are file path sources with outside lifetime/ownership
484 protected function hasVolatileSources( array $ops ) {
485 foreach ( $ops as $op ) {
486 if ( $op['op'] === 'store' && !isset( $op['srcRef'] ) ) {
487 return true; // source file might be deleted anytime after do*Operations()
494 protected function doQuickOperationsInternal( array $ops ) {
495 $status = $this->newStatus();
496 // Do the operations on the master backend; setting StatusValue fields...
497 $realOps = $this->substOpBatchPaths( $ops, $this->backends
[$this->masterIndex
] );
498 $masterStatus = $this->backends
[$this->masterIndex
]->doQuickOperations( $realOps );
499 $status->merge( $masterStatus );
500 // Propagate the operations to the clone backends...
501 foreach ( $this->backends
as $index => $backend ) {
502 if ( $index === $this->masterIndex
) {
503 continue; // done already
506 $realOps = $this->substOpBatchPaths( $ops, $backend );
507 if ( $this->asyncWrites
&& !$this->hasVolatileSources( $ops ) ) {
508 DeferredUpdates
::addCallableUpdate(
509 function () use ( $backend, $realOps ) {
510 $backend->doQuickOperations( $realOps );
514 $status->merge( $backend->doQuickOperations( $realOps ) );
517 // Make 'success', 'successCount', and 'failCount' fields reflect
518 // the overall operation, rather than all the batches for each backend.
519 // Do this by only using success values from the master backend's batch.
520 $status->success
= $masterStatus->success
;
521 $status->successCount
= $masterStatus->successCount
;
522 $status->failCount
= $masterStatus->failCount
;
527 protected function doPrepare( array $params ) {
528 return $this->doDirectoryOp( 'prepare', $params );
531 protected function doSecure( array $params ) {
532 return $this->doDirectoryOp( 'secure', $params );
535 protected function doPublish( array $params ) {
536 return $this->doDirectoryOp( 'publish', $params );
539 protected function doClean( array $params ) {
540 return $this->doDirectoryOp( 'clean', $params );
544 * @param string $method One of (doPrepare,doSecure,doPublish,doClean)
545 * @param array $params Method arguments
546 * @return StatusValue
548 protected function doDirectoryOp( $method, array $params ) {
549 $status = $this->newStatus();
551 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
552 $masterStatus = $this->backends
[$this->masterIndex
]->$method( $realParams );
553 $status->merge( $masterStatus );
555 foreach ( $this->backends
as $index => $backend ) {
556 if ( $index === $this->masterIndex
) {
557 continue; // already done
560 $realParams = $this->substOpPaths( $params, $backend );
561 if ( $this->asyncWrites
) {
562 DeferredUpdates
::addCallableUpdate(
563 function () use ( $backend, $method, $realParams ) {
564 $backend->$method( $realParams );
568 $status->merge( $backend->$method( $realParams ) );
575 public function concatenate( array $params ) {
576 $status = $this->newStatus();
577 // We are writing to an FS file, so we don't need to do this per-backend
578 $index = $this->getReadIndexFromParams( $params );
579 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
581 $status->merge( $this->backends
[$index]->concatenate( $realParams ) );
586 public function fileExists( array $params ) {
587 $index = $this->getReadIndexFromParams( $params );
588 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
590 return $this->backends
[$index]->fileExists( $realParams );
593 public function getFileTimestamp( array $params ) {
594 $index = $this->getReadIndexFromParams( $params );
595 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
597 return $this->backends
[$index]->getFileTimestamp( $realParams );
600 public function getFileSize( array $params ) {
601 $index = $this->getReadIndexFromParams( $params );
602 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
604 return $this->backends
[$index]->getFileSize( $realParams );
607 public function getFileStat( array $params ) {
608 $index = $this->getReadIndexFromParams( $params );
609 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
611 return $this->backends
[$index]->getFileStat( $realParams );
614 public function getFileXAttributes( array $params ) {
615 $index = $this->getReadIndexFromParams( $params );
616 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
618 return $this->backends
[$index]->getFileXAttributes( $realParams );
621 public function getFileContentsMulti( array $params ) {
622 $index = $this->getReadIndexFromParams( $params );
623 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
625 $contentsM = $this->backends
[$index]->getFileContentsMulti( $realParams );
627 $contents = []; // (path => FSFile) mapping using the proxy backend's name
628 foreach ( $contentsM as $path => $data ) {
629 $contents[$this->unsubstPaths( $path )] = $data;
635 public function getFileSha1Base36( array $params ) {
636 $index = $this->getReadIndexFromParams( $params );
637 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
639 return $this->backends
[$index]->getFileSha1Base36( $realParams );
642 public function getFileProps( array $params ) {
643 $index = $this->getReadIndexFromParams( $params );
644 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
646 return $this->backends
[$index]->getFileProps( $realParams );
649 public function streamFile( array $params ) {
650 $index = $this->getReadIndexFromParams( $params );
651 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
653 return $this->backends
[$index]->streamFile( $realParams );
656 public function getLocalReferenceMulti( array $params ) {
657 $index = $this->getReadIndexFromParams( $params );
658 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
660 $fsFilesM = $this->backends
[$index]->getLocalReferenceMulti( $realParams );
662 $fsFiles = []; // (path => FSFile) mapping using the proxy backend's name
663 foreach ( $fsFilesM as $path => $fsFile ) {
664 $fsFiles[$this->unsubstPaths( $path )] = $fsFile;
670 public function getLocalCopyMulti( array $params ) {
671 $index = $this->getReadIndexFromParams( $params );
672 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
674 $tempFilesM = $this->backends
[$index]->getLocalCopyMulti( $realParams );
676 $tempFiles = []; // (path => TempFSFile) mapping using the proxy backend's name
677 foreach ( $tempFilesM as $path => $tempFile ) {
678 $tempFiles[$this->unsubstPaths( $path )] = $tempFile;
684 public function getFileHttpUrl( array $params ) {
685 $index = $this->getReadIndexFromParams( $params );
686 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
688 return $this->backends
[$index]->getFileHttpUrl( $realParams );
691 public function directoryExists( array $params ) {
692 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
694 return $this->backends
[$this->masterIndex
]->directoryExists( $realParams );
697 public function getDirectoryList( array $params ) {
698 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
700 return $this->backends
[$this->masterIndex
]->getDirectoryList( $realParams );
703 public function getFileList( array $params ) {
704 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
706 return $this->backends
[$this->masterIndex
]->getFileList( $realParams );
709 public function getFeatures() {
710 return $this->backends
[$this->masterIndex
]->getFeatures();
713 public function clearCache( array $paths = null ) {
714 foreach ( $this->backends
as $backend ) {
715 $realPaths = is_array( $paths ) ?
$this->substPaths( $paths, $backend ) : null;
716 $backend->clearCache( $realPaths );
720 public function preloadCache( array $paths ) {
721 $realPaths = $this->substPaths( $paths, $this->backends
[$this->readIndex
] );
722 $this->backends
[$this->readIndex
]->preloadCache( $realPaths );
725 public function preloadFileStat( array $params ) {
726 $index = $this->getReadIndexFromParams( $params );
727 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
729 return $this->backends
[$index]->preloadFileStat( $realParams );
732 public function getScopedLocksForOps( array $ops, StatusValue
$status ) {
733 $realOps = $this->substOpBatchPaths( $ops, $this->backends
[$this->masterIndex
] );
734 $fileOps = $this->backends
[$this->masterIndex
]->getOperationsInternal( $realOps );
735 // Get the paths to lock from the master backend
736 $paths = $this->backends
[$this->masterIndex
]->getPathsToLockForOpsInternal( $fileOps );
737 // Get the paths under the proxy backend's name
739 LockManager
::LOCK_UW
=> $this->unsubstPaths( $paths[LockManager
::LOCK_UW
] ),
740 LockManager
::LOCK_EX
=> $this->unsubstPaths( $paths[LockManager
::LOCK_EX
] )
743 // Actually acquire the locks
744 return $this->getScopedFileLocks( $pbPaths, 'mixed', $status );
748 * @param array $params
749 * @return int The master or read affinity backend index, based on $params['latest']
751 protected function getReadIndexFromParams( array $params ) {
752 return !empty( $params['latest'] ) ?
$this->masterIndex
: $this->readIndex
;